﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smart.Core;
using Smart.ShortUrl.BU;
using Smart.ShortUrl.BU.Data;
using Smart.ShortUrl.BU.Model;

//using System.Net;

namespace Smart.ShortUrl.UI
{
    public class HomeController : Controller
    {
        //原生跳转
        //public ActionResult Index()
        //{
        //    return View();
        //}

        public void Index(string code)
        {
            string result = string.Empty;
            try
            {
                #region 网站访问日志，通过这个日志可以做使用分析
                //网站访问日志，通过这个日志可以做使用分析
                #endregion

                if (code == null)
                {
                    code = "";
                }
                else {

                    //重定向跳转页面
                    #region 使用数据库转换短路径
                    //使用数据库转换短路径
                    Dictionary<string, object> myParam = new Dictionary<string, object>();
                    object myObj = SYSShortUrlTransData.GetFieldValue(null, SYSShortUrlTrans.TargetUrl, SYSShortUrlTrans.MD5Code, code.Trim());
                    if (myObj != null)
                    {
                        result = myObj.ToString();
                    }
                    else
                    {
                        result = "";
                    }
                    #endregion
                }

                if (result != "")
                {
                    #region 重定向
                    Response.Redirect(result, true);
                    #endregion
                }
            }
            catch (Exception myEx)
            {
                throw myEx;
            }
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}